package Geometry;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.RectF;
import android.graphics.Paint.Style;

public class Rectangle extends Picture {

	// We need two points to specify a rectangle
	//   The upper left corner and the lower right corner
	// We'll let the 'basePoint' be the upper left corner
	// So, we need one field here for the lower right
	
	private PointF lowerRightCorner;
	
	
	
	
	public Rectangle(int drawColor, PointF basePoint, PointF lowerRightCorner) {
		super(drawColor, basePoint);
		this.lowerRightCorner = lowerRightCorner;
	}
	
	public Rectangle() {
		
	}



	public PointF getLowerRightCorner() {
		return lowerRightCorner;
	}

	public void setLowerRightCorner(PointF lowerRightCorner) {
		this.lowerRightCorner = lowerRightCorner;
	}

	@Override
	public void draw(Canvas canv) {
		Paint p = new Paint();
		p.setColor(getDrawColor());
		p.setStyle(Style.FILL);
		RectF r = new RectF(getBasePoint().x, getBasePoint().y, 
				getLowerRightCorner().x, getLowerRightCorner().y);
		canv.drawRect(r, p);
	}

	@Override
	public void move(float dx, float dy) {
		super.move(dx, dy);
		lowerRightCorner.x += dx;
		lowerRightCorner.y += dy;
	}

	@Override
	public boolean isInside(float x, float y) {
		// is (x,y) to the right of the left edge?
		boolean left = getBasePoint().x < x;  
		// is (x,y) to the left of the right edge?
		boolean right = x < lowerRightCorner.x;
		// is (x,y) below the top edge?
		boolean top = y > getBasePoint().y;
		// is (x,y) above the bottom edge?
		boolean bottom = y < lowerRightCorner.y;
		return left && right && top && bottom;
	}
	
	
}








